package com.hhss.qishi.mapper.system;

import com.hhss.qishi.entity.system.User;
import com.hhss.qishi.mapper.CapitalMapper;
import com.hhss.qishi.mapper.system.provider.UserProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author hhss
 * @date 2018年7月11日 
 */
@Mapper
@Repository
public interface UserMapper extends CapitalMapper<User> {
	
	@SelectProvider(type = UserProvider.class, method = "getListSQL")
	List<User> getList(@Param("user") User user);
	
	/**
	 * 查询用户及其相关的角色
	 * roles 角色集合启用懒加载
	 * @param user
	 * @return
	 */
	@SelectProvider(type = UserProvider.class, method = "getEntitySQL")
	@Results({
        @Result(/*id=true,*/column="id",property="id"),
        @Result(column="login_id",property="loginId"),
        @Result(column="password",property="password"),
        @Result(column="id",property="roles",
            many=@Many(
                    select="com.hhss.qishi.mapper.system.RoleMapper.getListByUserId",
                    fetchType=FetchType.LAZY
            )
        )
    })
	User getUserRoleById(@Param("user") User user);
	
}
